#
# @lc app=leetcode.cn id=682 lang=python3
#
# [682] 棒球比赛
#

# @lc code=start
class Solution:
    def calPoints(self, operations: List[str]) -> int:
        num = list()
        for operation in operations:
            if operation == 'C':
                num.pop()
            else:
                if operation == '+':
                    num.append(num[-2] + num[-1])
                elif operation == 'D':
                    num.append(2 * num[-1]) 
                else:
                    num.append(int(operation))
            
        return sum(num)
# @lc code=end

